package com.fsy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fsy.entities.Modules;
import com.fsy.entities.Users;
import com.fsy.service.UsersService;
import com.fsy.mapper.UsersMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 凡凡
* @description 针对表【users】的数据库操作Service实现
* @createDate 2022-04-18 10:00:29
*/
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users>
    implements UsersService{
    @Resource
    private UsersMapper usersMapper;

    /**
     * 根据条件查询用户
     * @param users
     * @return
     */
    public List<Users> selectUsers(Users users){
        int page = users.getPage();
        int limit = users.getLimit();
        int offset = (page-1)*limit;
        users.setPage((page-1)*limit);
        users.setOffset(offset);//计算偏移量
        return usersMapper.selectUsers(users);
    }

    /**
     * 根据条件查询用户数量
     * @param users
     * @return
     */
    public int selectCounts(Users users){
        return usersMapper.selectCounts(users);
    }

    /**
     * 判断密码是否正确，来增加密码错误次数
     * @param users
     * @return
     */
    public int incorrecPassword(Integer id){
        return usersMapper.incorrecPassword(id);
    }

    @Override
    public List<Modules> getPermission(String loginName, String password) {
        return usersMapper.getPermission(loginName,password);
    }

    @Override
    public Integer updatePassWord(Integer id, String password) {
        return usersMapper.updatePassWord(id, password);
    }

    @Override
    public Users selectLogins(Integer id, String password) {
        return usersMapper.selectLogins(id, password);
    }
}




